package cn.yunhe.daoImpl;


import org.apache.ibatis.session.SqlSession;

import cn.yunhe.dao.CustomerDao;
import cn.yunhe.entity.Customer;
import cn.yunhe.factory.SqlSessionFactoryUtil;

public class CustomerDaoImpl implements CustomerDao {

	public boolean addCustomer(Customer customer) {
		SqlSession sqlSession = null;
		int result = 0;
		try {
			sqlSession = SqlSessionFactoryUtil.getSqlSession();
			result = sqlSession.insert("customerMapper.addCustomer",customer);
			sqlSession.commit();
		} catch (Exception e) {
			e.printStackTrace();
			sqlSession.rollback();
		} finally {
			if (sqlSession != null) {
				sqlSession.close();
			}
		}
		return result == 0 ? false : true;
	}

	public Customer loginCustomer(Customer customer) {
		SqlSession sqlSession = null;
		Customer cus = null;
		try {
			sqlSession = SqlSessionFactoryUtil.getSqlSession();
			cus = sqlSession.selectOne("customerMapper.loginCustomer",customer);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (sqlSession != null) {
				sqlSession.close();
			}
		}
		return cus;
	}

}
